#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
};

int sizenum(struct TreeNode* root)
{
    if (root == NULL)
        return 0;

    return sizenum(root->left) + sizenum(root->right) + 1;
}

int  i = 0;

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int* a = (int*)malloc(sizeof(int) * sizenum(root));
    returnSize = a;
    if (root == NULL)
    {
        return NULL;
    }
    returnSize[i++] = root->val;
    preorderTraversal(root->left, returnSize);
    preorderTraversal(root->right, returnSize);
    return returnSize;
}

